// components/custom-steps/index.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    steps: {
      type: Array,
      value: []
    },
    active: Number
  },

  /**
   * 组件的初始数据
   */
  data: {
    progressPercent: 0
  },


  attached() {
    const { steps, active } = this.data
    const progressPercent = this.computeProgressPercent(steps, active)
    this.setData({ progressPercent })
  },

  /** 组件监听 */
  observers: {
    'steps, active': function(newSteps, newActive) {
      const progressPercent = this.computeProgressPercent(newSteps, newActive)
      this.setData({ progressPercent })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    /** 根据传入的步骤控制进度条的占比 */
    computeProgressPercent(steps, active){
      const stepsLen = steps.length - 1
      console.log(stepsLen, active);
      return  Math.round(100 / (stepsLen * 2)) * active * 2
    }
  }
})